<?

class StatsHelper {

	 public $mysql;
	 public $user;
	 
	 public function __construct($user,$mysql){
		  $this->mysql = $mysql;
		  $this->user = $user;
	 }
	 
	 public function getNbOffres(){
		  $mysql = $this->mysql;
		  $query = "SELECT count(*) as nb FROM offre WHERE user = '$this->user';";
		  $res = $mysql->query($query);
		  if($mysql->errno != 0) throw new Exception ("Erreur MySQL : ".$mysql->error);
		  $line = $res->fetch_object();
		  $nb = $line->nb;
		  return $nb;
	 }
	 public function getNbProjets(){
		  $mysql = $this->mysql;
		  $query = "SELECT valid,count(*) as nb FROM projet WHERE user = '$this->user' GROUP BY valid;";
		  $res = $mysql->query($query);
		  if($mysql->errno != 0) throw new Exception ("Erreur MySQL : ".$mysql->error);
		  $aProjets["VALIDE"] = 0;
		  $aProjets["WORKING"] = 0;
		  $aProjets["DONE"] = 0;
		  while($line = $res->fetch_object()){
				$aProjets[$line->valid] = $line->nb;
		  }
		  return $aProjets;
	 }
	 

}